<!--<link rel="stylesheet" type="text/css" href="css/page.css"/>-->
<style type="text/css">
button{cursor: pointer;}
.wrap{width:80%;float:right;}
table{width:100%; line-height:23px;margin:10px 0; border-color:#d5dce2;}
th,td{ text-align:center; border-color:#d5dce2; line-height:30px;}
th{background:#f2f9ff;}
.pri{width:109px;height:22px;text-align:center;}
.fenyeiWrap{width:85%;}
#tplid{display:none;}
.addcp {background: url("../images/btn23_two1.png") no-repeat scroll left top rgba(0, 0, 0, 0);display: inline-block;height: 23px;padding-left: 8px;text-decoration: none;}
.addcp span {background: url("../images/btn23_two1.png") no-repeat scroll right top rgba(0, 0, 0, 0);color: #FFFFFF;display: inline-block;font-size: 12px;font-weight: bold;height: 23px;line-height: 23px;padding-right: 8px;}
.ty{background:#f0851d; border:1px solid #a9550f; height:25px;width:75px; color:#fff; padding-bottom:2px;  padding-bottom:0px\9; }
.back{float:right; font-weight:bold;}
#txt{margin-right:15px; color:#888;}
#class{margin-right:25px;}
tr{border-bottom:1px solid #B0DFFD; height:35px;}
tr.tt{border-top:1px solid #B0DFFD; background:#F3FAFF;height:30px;}
.space{height:10px;}
.pri{width:50px;height:20px;text-align:center;line-height:20px;}
.p_t{display:block; position:absolute; right:-19px; top:-15px; top:4px\9; width:40px;}
.add,.rude{display:block; width:10px; height:11px; border:1px solid; line-height:9px; line-height:8px\9; padding-right:1px; font-size:15px; cursor:pointer;}
.add{position: absolute;right:-40px; top:-5px;}
.rude{position:absolute; right:30px; top:-6px;}
</style>
<script type="text/javascript">
function ty(){
	var h=$.ajax({url:"call/hasTpl.php",async:false}).responseText;
	if(h){
		$("#tplid").show();
	}
	else{
		if(confirm('检测到您尚未创建过模板,是否创建?')){
			window.open('addtpl.html','_blank');
		}
	}
}
function xzmb(){
	var t=$('#tplid').val();
	if(t>0){
		$.getJSON("call/getTpl.php",{tplid:t},function(tpl){
			$(":checkbox").each(function(){
				var ckbox=$(this);
				if(ckbox.val()!="all"){
					if(!isNaN(tpl[ckbox.val()])){
						ckbox.attr("checked",true).parent().parent().find(":text").attr("disabled",false).val(($("#stype").length && $("#stype").attr("checked") ? 0 :Number(ckbox.parent().parent().children().eq(2).html()))+Number(tpl[ckbox.val()]));
					}
					else{
						ckbox.attr("checked",false).parent().parent().find(":text").attr("disabled",true);
					}
				}
			});
		});
	}
	else if(t==-1){
		window.open('addtpl.html','_blank');
	}
}
function add(){
	tid="";
	pri="";
	$(":checkbox").each(function(){
		var ckbox=$(this);
		if(ckbox.attr("checked")){
			tid+=ckbox.val()+"|";
			pri+=ckbox.parent().parent().find(":text").val()+"|";
		}
	});
	if(tid)tid=tid.substr(0,tid.length-1);
	if(pri)pri=pri.substr(0,pri.length-1);
	$('#overlyWrap').hide()
	$('#mask').css('visibility','hidden');
	alert($.ajax({url:"pri_tpl.php",data:{title:$("#tpl_tt").val(),perc:$("#perc").val(),dpt:$("#dpt").val(),tid:tid,pri:pri,act:"add"},async:false}).responseText);
}
$(document).ready(function(){
    $(".ckall").click(function(){ // 全选
        $(".tids").attr("checked",true).parent().parent().find(':text').attr('disabled',false);
    });
    $(".reck").click(function(){// 反选
        $(".tids").each(function(index,element){
            $(this).attr("checked",!this.checked).parent().parent().find(':text').attr('disabled',!this.checked);
        });
    });
    $(".add").click(function(){
        var cs = 0;
        $(".pri").each(function(index,element){
            if(!element.disabled){
                cs = Number($(this).val());
                if(cs==0) cs = Number($(".gpri").eq(index).html());
                cs = cs + 1;
                $(this).val(cs);
            }
            
        });
    });
    
    $(".rude").click(function(){
        var cs = 0;
        $(".pri").each(function(index,element){
            if(!element.disabled){
                cs = Number($(this).val());
                cs = cs - 1;
                if(cs < Number($(".gpri").eq(index).html()) || cs < 1){
                    cs = Number($(".gpri").eq(index).html());
                }
                $(this).val(cs);
            }
            
        });
    });
});
</script>
<div class="wrap">
	<iframe name="ifr" style="display:none;"></iframe>
  <form action="addtpl.php" method="post" target="ifr">
	<input type="hidden" name="id" value="<?=$id?>" />
	<b>模板名称：</b><input type="text" name="title" value="<?=$title?>"/>
	<button type="submit" onclick="" class="ty"><?=$act?>模板</button>
<?	if($id){?>
	<a href="javascript:void(0);" onclick="history.go(-1);return false;" class="back"><<返回</a>
<?	}?>
<div class="martp5">
       <a href="javascript:void(0);" class="ckall">全选</a> 
       <a href="javascript:void(0);" class="reck">反选</a> 
    </div>
	<table border="1">
		<tr>
			<th >购买权限</th>
			<th>产品名称</th>
			<th>供货价</th>
			<th width="180">
				<div style="position:relative; display:inline-block;" >
                <span  class="rude">-</span>
                <span class="add">+</span><span class="p_t">结算价</span></div>
			</th>
		</tr>
	<?	foreach($prod as $p){
			if(!$id || isset($tpl[$p['id']])){
				$checked="checked";
				$pri=$id?$p['pri']+$tpl[$p['id']]:$p['pri'];
				$disable="";
			}
			else{
				$checked="";
				$pri="";
				$disable="disabled";
			}?>
		<tr>
			<td><input type="checkbox" name="pid[]" <?=$checked?> value="<?=$p['id']?>" class="tids" onchange="$(this).parent().parent().find(':text').attr('disabled',!this.checked);" class="tids"/></td>
			<td><?=$p['p_name']?></td>
			<td class="gpri"><?=$p['pri']?></td>
			<td><input class="pri" type="text" <?=$disable?> name="pri[<?=$p['id']?>]" value="<?=$pri?>" /></td>
		</tr>
	<?	}?>
	</table>
	
	<?//page($total,$currentPage,$pageSize);?>
  </form>
</div>